//
//  HHMoneyDetailReform.m
//  HHBroker
//
//  Created by He Wei on 10/19/15.
//  Copyright © 2015 harry. All rights reserved.
//

#import "HHMoneyDetailReform.h"
#import "WMString-Utilities.h"

@implementation HHMoneyDetailReform

+ (NSArray *)reformDataWithRespone:(id)response type:(NSInteger)type
{
    NSArray *titleArray = [self arrayWithType:type];
    if (!titleArray || titleArray.count == 0 || !response) {
        return [[NSArray alloc] init];
    }
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:10];
    for (NSDictionary *dic in titleArray) {
        NSString *title = [dic objectForKey:@"title"];
        NSString *key = [dic objectForKey:@"key"];
        NSString *value = [response objectForKey:key];
        
        if ([value isKindOfClass:[NSNull class]]) {
            continue;
        }
        if (title && value) {
            value = [NSString stringWithFormat:@"%@", value];
            value = [self transformStringWithKey:key value:value response:response];
            NSDictionary *moneyDetail = @{@"title":title,
                                          @"value":value};
            [array addObject:moneyDetail];
        }
    }
    return array;
}

+ (NSArray *)arrayWithType:(NSInteger)type
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"JYMoneyDetailProperty" ofType:@"plist"];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
    if (!dic) {
        return nil;
    }
    NSArray *array = [dic objectForKey:[NSString stringWithFormat:@"%@", @(type)]];
    if (!array) {
        return nil;
    }
    return array;
}

+ (NSString *)transformStringWithKey:(NSString *)key value:(NSString *)value response:(id)response
{
    if ([key isEqualToString:@"financial_audit_time"] || [key isEqualToString:@"sign_time"] || [key isEqualToString:@"over_time"]) {
        return [NSString timeStamp:value];
    }
    if ([key isEqualToString:@"month"]) {
        return [NSString stringWithFormat:@"%@个月", value];
    }
    if ([key isEqualToString:@"pro_cit_name"]) {
        NSString *city = [response objectForKey:@"cit_name"];
        return [NSString stringWithFormat:@"%@-%@", value, city];
    }
    if ([key isEqualToString:@"service_status"]) {
        return [self contractDesWithKey:value];
    }
    return value;

}

+ (NSString *)contractDesWithKey:(NSString *)key
{
    // 1未签合同 2已录入 3到款确认 5暂停 7已退款（放弃的） 8关单待审核  9关单成功 10 退款审核中 11 申请退款失败 12申请关单失败 13总监审核(特批) 14总经理审核(特批)'
    NSDictionary *dic = @{@"1": @"未签合同",
                          @"2": @"已录入",
                          @"3": @"到款确认",
                          @"5": @"暂停",
                          @"7": @"已退款（放弃的）",
                          @"8": @"关单待审核",
                          @"9": @"关单成功",
                          @"10":@"退款审核中",
                          @"11":@"申请退款失败",
                          @"12":@"申请关单失败",
                          @"13":@"总监审核(特批)",
                          @"14":@"总经理审核(特批)"};
    NSString *des = [dic objectForKey:key];
    if (des) {
        return des;
    } else {
        return key;
    }
}

@end
